<!--
 * @Author: 马潭龙
 * @Date: 2022-01-18 15:29:01
 * @LastEditTime: 2022-01-18 15:59:41
 * @LastEditors: 马潭龙
 * @Description: 
 * @FilePath: \devlomp\icm-vue-master\src\views\hifar\knowledge\knowledgeRight.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <a-card :bordered="false" style="minheight: 560px">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="工具名称">
              <a-input placeholder="工具名称" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建人">
              <a-input placeholder="请输入创建人" v-model="queryParam.createBy"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="refresh" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('hf_pm_project_tool_records')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        rowKey="id"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        class="j-table-force-nowrap"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a style="color:red">删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <knowledgeRightModal ref="modalForm" :tree="treeData" @ok="loadData" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import knowledgeRightModal from './modules/knowledgeRightModal'
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil'

export default {
  name: 'HfPmProjectToolRecordsList',
  mixins: [JeecgListMixin],
  components: {
    knowledgeRightModal,
  },
  props: {
    tree: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    tree: {
      immediate: true,
      handler(val) {
        this.treeData = val
      },
    },
  },
  data() {
    return {
      description: '项目工具管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '知识名称',
          align: 'center',
          dataIndex: 'title',
        },
        {
          title: '所属项目',
          align: 'center',
          dataIndex: 'parentId',
          customRender:(text)=>{
            this.tree.forEach((item)=>{
              if(text==item.id){
                return text=item.title
              }
            })
        }
        },
        {
          title:'关键词',
          align:'center',
          dataIndex: 'keyWords'
        },
        {
          title: '知识类型',
          align:'center',
          dataIndex: 'recordType',
          customRender: (text) => {
            //字典值翻译通用方法
            return filterDictTextByCache('pm_project_knowledge_type', text);
          }
        },
        {
          title: '附件(数量)',
          align: 'center',
          dataIndex: 'fileNum',
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remarks',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/pm/hfPmProjectKnowledgeRecords/list',
        delete: '/pm/hfPmProjectKnowledgeRecords/delete',
        deleteBatch: '/pm/hfPmProjectKnowledgeRecords/deleteBatch',
        exportXlsUrl: '/pm/hfPmProjectToolRecords/exportXls',
        importExcelUrl: 'pm/hfPmProjectToolRecords/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      treeData: [],
      treeId: '',
    }
  },
  created() {
    
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'title', text: '名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'toolsClassName', text: '工具分类', dictCode: '' })
      fieldList.push({ type: 'string', value: 'recordType', text: '工具类型', dictCode: 'pm_project_knowledge_type' })
      fieldList.push({ type: 'string', value: 'attachmentNum', text: '附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'remarks', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    },

    handleAdd: function () {
      this.$refs.modalForm.add();
      this.$refs.modalForm.title = "新增";
      this.$refs.modalForm.disableSubmit = false;
      this.$nextTick(() => {
        this.$refs.modalForm.$refs.realForm.$refs.uploadFile.tableData = []
        this.$refs.modalForm.$refs.realForm.$refs.uploadFile.fileList = []
      })
    },
    refresh() {
      this.queryParam = {}
      this.loadData();
    },
    loadData(arg) {
      if(arg!=1){
        this.treeId=arg
      }else {
        arg=1
        this.ipagination.current = 1;
      }
      var params = {
        ...this.getQueryParams(),
        parentId:this.treeId,
        isFolder: '0',
      }
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records||res.result;
          if(res.result.total)
          {
            this.ipagination.total = res.result.total;
          }else{
            this.ipagination.total = 0;
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>